import { BasicDelModel } from '../model/baseModel';
import { DetailSearchModel, DetailVOModel, DictSearchModel, DictVOModel } from './model/dictModel';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  DictBaseApi = '/sys/dict',
  DIctDetailBaseApi = '/sys/dict/detail',
  GetDictListApi = '/sys/dict/select-list',
  GetDetailListApi = '/sys/dict/detail/select-list',
}

/**
 * @description: 获取数据字典列表数据
 */
export const getDictPageApi = (data: DictSearchModel) => {
  return defHttp.post({ url: Api.DictBaseApi + '/page', data });
};

/**
 * @description: 获取数据字典集合数据
 */
export const getDictListApi = () => {
  return defHttp.post({ url: Api.GetDictListApi });
};

/**
 * @description: 新增数据字典
 */
export const saveDictApi = (data: DictVOModel) => {
  return defHttp.post({ url: Api.DictBaseApi + '/add', data });
};

/**
 * @description: 修改数据字典
 */
export const updateDictApi = (data: DictVOModel) => {
  return defHttp.post({ url: Api.DictBaseApi + '/edit', data });
};

/**
 * @description: 删除数据字典
 */
export const delDictApi = (ids: string) => {
  const data: BasicDelModel = {
    ids: Array.isArray(ids) ? ids : [ids]
  }
  return defHttp.post({ url: Api.DictBaseApi + '/delete', data });
};

/**
 * @description: 获取字典详细列表数据
 */
export const getDictDetailPageApi = (data: DetailSearchModel) => {
  return defHttp.post({ url: Api.DIctDetailBaseApi + '/page', data });
};

/**
 * @description: 获取数据字典的字典详细信息
 */
export const getDictDetailListApi = (data: DetailVOModel) => {
  return defHttp.post({ url: Api.GetDetailListApi, data });
};

/**
 * @description: 新增字典详细
 */
export const saveDictDetailApi = (data: DetailVOModel) => {
  return defHttp.post({ url: Api.DIctDetailBaseApi + '/add', data });
};

/**
 * @description: 修改字典详细
 */
export const updateDictDetailApi = (data: DetailVOModel) => {
  return defHttp.post({ url: Api.DIctDetailBaseApi + '/edit', data });
};

/**
 * @description: 删除字典详细
 */
export const delDictDetailApi = (ids: string[]) => {
  const data: BasicDelModel = {
    ids: ids
  }
  return defHttp.post({ url: Api.DIctDetailBaseApi + '/delete', data });
};
